package com.ibeetl.dao.edao;

import com.ibeetl.dao.common.TestServiceInterface;
import com.ibeetl.dao.edao.entity.EdaoUser;
import io.edap.x.dao.EntityDao;
import org.springframework.beans.factory.annotation.Autowired;

import java.sql.SQLException;
import java.util.Arrays;

import static io.edap.x.dao.QueryParam.p;

public class EdapPerformaceTestService implements TestServiceInterface {

    @Autowired
    private EntityDao<EdaoUser> dao;

    int index = 1;

    @Override
    public void testAdd() {
        EdaoUser user = createUser();
        try {
            dao.insert(user);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    private EdaoUser createUser() {
        EdaoUser user = new EdaoUser();
        user.setId(index++);
        user.setCode("abc");
        return user;
    }

    @Override
    public void testUnique() {
        try {
            dao.findOne("select * from sys_user where id=?", Arrays.asList(p(1)));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void testUpdateById() {

        EdaoUser user = new EdaoUser();
        try {
            user.setId(1);
            user.setCode("hello");
            dao.updateById(user);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void testPageQuery() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void testExampleQuery() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void testOrmQUery() {
        throw new UnsupportedOperationException();
    }
}
